import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';
import { render, formattingMin, formattingDay, formatTimestamp } from '/@/utils/common/renderUtils';
//列表数据
export const columns : BasicColumn[] = [
	{
		title: '状态',
		align: "center",
		dataIndex: 'stats_dictText'
	},
	{
		title: '代理商等级',
		align: "center",
		dataIndex: 'agentGrade'
	},
	{
		title: '昵称',
		align: "center",
		dataIndex: 'nickname'
	},
	{
		title: '真实姓名',
		align: "center",
		dataIndex: 'realname'
	},
	{
		title: '代号',
		align: "center",
		dataIndex: 'codename'
	},
	{
		title: '电话号码',
		align: "center",
		dataIndex: 'phone'
	},
	{
		title: '学校id',
		align: "center",
		dataIndex: 'schoolid_dictText'
	},
	{
		title: '备注',
		align: "center",
		dataIndex: 'extInfors',
		customRender: ({ text, column }) => {
			if (text == null || text == {}) {
				return ''
			}
			if (text.indexOf("remark") > -1) {
				let remark = JSON.parse(text).remark
				if (!remark) {
					remark = JSON.parse((JSON.parse(text))).remark
				}
				return remark;
			} else {
				return ""
			}
		},

	},
	{
		title: '已提现佣金',
		align: "center",
		sorter: true,
		dataIndex: 'alreadycommissionwithdrawn'
	},
	{
		title: '团队',
		align: "center",
		sorter: true,
		dataIndex: 'teamId_dictText'
	},
	{
		title: '是否团队长',
		align: "center",
		sorter: true,
		dataIndex: 'teamleaderornot_dictText'
	},
	{
		title: '团队人数',
		align: "center",
		sorter: true,
		dataIndex: 'teamagentsize'
	},
	{
		title: '累计收益',
		align: "center",
		sorter: true,
		dataIndex: 'accumulatedincome'
	},
	{
		title: '当前可提现佣金',
		align: "center",
		sorter: true,
		dataIndex: 'maywithdrawablecommission'
	},
	{
		title: '团队收益',
		align: "center",
		sorter: true,
		dataIndex: 'teamrevenue'
	},
];
//查询数据
export const searchFormSchema : FormSchema[] = [
	{
		label: "状态",
		field: 'stats',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "agent_stats"
		},
		//colProps: {span: 6},
	},
	{
		label: "真实姓名",
		field: 'realname',
		component: 'Input',
		//colProps: {span: 6},
	},
	{
		label: "代号",
		field: 'codename',
		component: 'Input',
		//colProps: {span: 6},
	},
	{
		label: "电话号码",
		field: 'phone',
		component: 'Input',
		//colProps: {span: 6},
	},
	{
		label: "学校",
		field: 'schoolid',
		component: 'JSearchSelect',
		componentProps: {
			dict: "couple_school,title,id"
		},
		//colProps: {span: 6},
	},
	{
		label: "是否团队长",
		field: 'teamleaderornot',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "is"
		},
		//colProps: {span: 6},
	},
];
//表单数据
export const formSchema : FormSchema[] = [
	{
		label: '',
		field: 'isUpdate',
		component: 'Input',
		show: false
	},
	{
		label: '状态',
		field: 'stats',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "agent_stats"
		},
		show: ({ values }) => {
			return values.isUpdate == true
		}
	},
	{
		label: '代理商等级',
		field: 'agentGrade',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "sys_category,name,id,pid='1724609720825683970'"
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择代理商等级!' },
			];
		},
	},


	{
		label: '真实姓名',
		field: 'realname',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入真实姓名!' },
			];
		},
	},
	{
		label: '代号',
		field: 'codename',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入代号!' },
			];
		},
	},
	{
		label: '选择团队',
		field: 'teamId',
		component: 'JSearchSelect',
		componentProps: {
			dict: 'couple_distribution_team,title,id',
			async: true
		},
	},
	{
		label: '电话号码',
		field: 'phone',
		component: 'Input',
	},
	{
		label: '选择学校',
		field: 'schoolid',
		component: 'JSearchSelect',
		componentProps: {
			dict: "couple_school,title,id",
			async: true
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入学校id!' },
			];
		},
	},
	/* 	{
			label: '其余信息',
			field: 'extinfors',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入其余信息!' },
				];
			},
		}, */
	{
		label: '已提现佣金',
		field: 'alreadycommissionwithdrawn',
		component: 'InputNumber',
	},
	{
		label: '是否团队长',
		field: 'teamleaderornot',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "is"
		},
		required: true
	},
	{
		label: '备注',
		field: 'remark',
		component: 'InputTextArea',//TODO 注意string转换问题
		required: true
	},
	{
		label: '团队人数',
		field: 'teamagentsize',
		component: 'InputNumber',
	},
	{
		label: '累计收益',
		field: 'accumulatedincome',
		component: 'InputNumber',
	},
	{
		label: '当前可提现佣金',
		field: 'maywithdrawablecommission',
		component: 'InputNumber',
	},
	{
		label: '团队收益',
		field: 'teamrevenue',
		component: 'InputNumber',
	},
	// TODO 主键隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
];

//子表列表数据
export const bsUserlayoutAgentReportColumns : BasicColumn[] = [
	//：- ，AlreadyArranged- 已安排，: -关闭接单，escorting: -
	{
		title: '状态',
		align: "center",
		dataIndex: 'stats',
		customRender: ({ text }) => {
			if (text == 'AlreadyArranged') {
				return '已安排'
			} else if (text == 'Unscheduled') {
				return '可接单'
			} else if (text == 'Close') {
				return '关闭接单'
			} else if (text == 'Escorting') {
				return '带团中'
			}
		}
	},
	/* 	{
			title: '领队id',
			align: "center",
			dataIndex: 'agentid'
		}, */
	{
		title: '报备时间',
		align: "center",
		dataIndex: 'reportdate',
		customRender: ({ text }) => {
			let o = formatTimestamp(text);
			return o.split(" ")[0]
		}
	},
	/* 	{
			title: '其余信息其它信息',
			align: "center",
			dataIndex: 'extinfors'
		}, */
];
//子表表单数据
export const bsUserlayoutAgentReportFormSchema : FormSchema[] = [
	// TODO 子表隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
	{
		label: '状态',
		field: 'stats',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '可接单', value: 'Unscheduled' },
				{ label: '已安排', value: 'AlreadyArranged' },
				{ label: '关闭接单', value: 'Close' },
				{ label: '带团中', value: 'Escorting' },
			],
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入选择状态' },
			];
		},
	},
	{
		label: '领队id',
		field: 'agentid',
		component: 'Input',
		show: false
		/* 	dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入领队id!' },
				];
			}, */
	},
	{
		label: '报备时间',
		field: 'reportdateString',
		component: 'DatePicker',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择报备时间!' },
			];
		},
	},
	/* {
		label: '其余信息其它信息',
		field: 'extinfors',
		component: 'InputTextArea',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入其余信息其它信息!' },
			];
		},
	}, */
];

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData) : FormSchema[] {
	// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
	return formSchema;
}